/**
 * 
 */
package com.sci.web.daoimpl;

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sci.web.bean.Enterprise_Base;
import com.sci.web.bean.User;
import com.sci.web.bean.User_Enterprise;
import com.sci.web.dao.EnterpriseInfoManageDao;

/**
 * @author BaiFuyou
 * @date: Oct 12, 2011 3:07:49 PM
 */
public class EnterpriseInfoManageDaoImpl extends SqlMapClientDaoSupport implements EnterpriseInfoManageDao {

	@Override
	public Enterprise_Base getEnterprise_BaseInfoByUserId(int user_id) {
		// TODO Auto-generated method stub
		return (Enterprise_Base) super.getSqlMapClientTemplate().queryForObject("enterpriseinfomanage.getenterpriseinfobyuserid", user_id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Base> getAllEnterprise_BaseByCityidAndUserId(int city_id, int flag) {
		// TODO Auto-generated method stub
		List<Enterprise_Base> list = null;
		/**
		 * 1未审核；2未通过；3审核通过
		 */
		if (flag == 1) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getnotcheckuserandenterprise", city_id);
			System.out.println(list);
		}
		if (flag == 3) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getpasscheckuserandenterprise", city_id);
		}
		if (flag == 2) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getnotpasscheckuserandenterprise", city_id);
		}

		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Base> getAllEnterprise_BaseByCityidAndUserId(int flag) {
		// TODO Auto-generated method stub
		List<Enterprise_Base> list = null;
		/**
		 * 1未审核；2未通过；3审核通过
		 */
		if (flag == 1) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getnotcheckuserandenterpriseadmin");
		}
		if (flag == 2) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getpasscheckuserandenterpriseadmin");
		}
		if (flag == 3) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getnotpasscheckuserandenterpriseadmin");
		}

		return list;
	}

	@Override
	public boolean isEnterpriseInfoChecking(int id) {
		// TODO Auto-generated method stub
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().queryForObject("enterpriseinfomanage.getenterpriseischecking", id);
		if (index > 0)
			return true;
		else
			return false;
	}

	@Override
	public boolean notPassCheckEnterpriseUser(int userid) {
		// TODO Auto-generated method stub
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.notpasscheckenterpriseuser", userid);
		if (index > 0)
			return true;
		else
			return false;
	}

	@Override
	public boolean passCheckEnterprseUser(int userid) {
		// TODO Auto-generated method stub notpasscheckenterpriseuser
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.passcheckenterpriseuser", userid);
		if (index > 0)
			return true;
		else
			return false;
	}

	@Override
	public List<Enterprise_Base> getEnterprsieBase_reload(String sql) {
		// TODO Auto-generated method stub
		List<Enterprise_Base> list = null;
		list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getresult_reload", sql);
		if (list != null)
			return list;
		else
			return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User_Enterprise> getUser_Enterprise(int cityid) {
		// TODO Auto-generated method stub
		List<User_Enterprise> list = null;
		if (cityid == -1) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getalluser_qyyhgl_superman");
		} else {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getalluser_qyyhgl_normal", cityid);
		}
		return list;
	}

	@Override
	public boolean deleteUserById(int userid) {
		// TODO Auto-generated method stub
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.deleteuserbyid", userid);
		if (index > 0) {
			return true;
		} else
			return false;
	}

	@Override
	public boolean updateUserPassword(int userid) {
		// TODO Auto-generated method stub
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.updateuserpwdbyid", userid);
		if (index > 0) {
			return true;
		} else
			return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Base> getChangedEnterpriseBaseInfo(int cityid) {
		// TODO Auto-generated method stub
		List<Enterprise_Base> list = null;
		/**
		 * 超级用户信息
		 */
		if (cityid == -1) {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getallchangedeninfosuperman");
		} else {
			list = super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getallchangedeninfonormaluser", cityid);
		}
		if (list != null) {
			return list;
		} else
			return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Base> getFristValue(int id) {
		// TODO Auto-generated method stub
		return super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getfristvalue", id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Enterprise_Base> getSecondValue(int id) {
		// TODO Auto-generated method stub
		return super.getSqlMapClientTemplate().queryForList("enterpriseinfomanage.getsecondvalue", id);
	}

	@Override
	public boolean notPassChangedInfo(int id) {
		// TODO Auto-generated method stub
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.notpasschangedinfo", id);
		if (index > 0) {
			return true;
		} else
			return false;
	}

	@Override
	public boolean passChangednfo(int id) {
		// TODO Auto-generated method stub
		// int index = -1;
		// int result = -1;
		// index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.passchangedinfo", id);
		// if (index > 0) {
		// result = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.changeresultenterprise_updatestatus_2", id);
		// }
		// if (result > 0) {
		// return true;
		// } else
		// return false;
		Enterprise_Base eb = (Enterprise_Base) super.getSqlMapClientTemplate().queryForObject("enterpriseinfomanage.getbefeforeenterpriseinfo", id);
		int index = -1;
		index = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.updatepasschangedinfo", eb);
		int index_update = -1;
		index_update = (Integer) super.getSqlMapClientTemplate().update("enterpriseinfomanage.changeresultenterprise_updatestatus_2", id);
		if (index > 0 && index_update > 0) {
			return true;
		} else {
			return false;
		}
	}
}
